import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/:pathMatch(.*)*', // 匹配所有未定义的路径
    redirect: '/404', // 重定向到 404 页面
  },
  {
    path: '/404',
    component: () => import('@/views/404.vue'), // 懒加载页面组件
  },
  {
    path: '/',
    component: () => import('@/views/Login.vue'),
  },
  {
    path: '/login',
    component: () => import('@/views/Login.vue'),
  },
  {
    path: '/home',
    component: () => import('@/views/Home.vue'),
    meta: { title: '主页' },
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        component: () => import('@/views/Dashboard.vue'),
        meta: { title: '信息概览' },
      },
      {
        path: '/center',
        component: () => import('@/views/UserCenter.vue'),
        meta: { title: '个人中心' },
      },
      {
        path: '/user/index',
        component: () => import('@/views/user/Index.vue'),
        meta: { title: '用户管理', parent: '权限管理' },
      },
      {
        path: '/role/index',
        component: () => import('@/views/role/Index.vue'),
        meta: { title: '角色管理', parent: '权限管理' },
      },
      {
        path: '/dict/index',
        component: () => import('@/views/dict/Index.vue'),
        meta: { title: '字典管理', parent: '系统配置' },
      },
      {
        path: '/permission/index',
        component: () => import('@/views/permission/Index.vue'),
        meta: { title: '权限管理', parent: '系统配置' },
      },
    ],
  },
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
